package com.room.user.listen;

import com.rabbitmq.client.Channel;
import com.room.user.util.MsgUtil;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.io.IOException;

@RabbitListener(queues = "RoomUser")
@Component
public class SendYzmListen {
    @Autowired
    private StringRedisTemplate redisTemplate;

    @RabbitHandler
    public void sendYzm(String phone, Message message, Channel channel){
        //调用发短信工具类,获取手机号,发送短信
        String s = MsgUtil.sendMsg(phone);
        //把手机验证码存入到redis
        redisTemplate.opsForValue().set(phone,s);


        try {
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


}
